<link rel="stylesheet" href="components/com_sale_tsc_order/assets/jquery-ui.css"/>
<link rel="stylesheet" href="components/com_sale_tsc_order/assets/style2.css"/>
<script language="javascript" src="components/com_sale_tsc_order/assets/jquery-1.8.2.js"></script>
<script language="javascript" src="components/com_sale_tsc_order/assets/jquery-ui.js"></script>
<script type="text/javascript">
    function submit_form(a,b)
    {
        document.frm1['task'].value = a;
        document.frm1['id_bill'].value = b; 
        document.frm1.submit();
    }
    
    function order()
    {
        window.location.href = "index.php?option=com_sale_tsc_order&task=order";
    return;
    }
</script>
<script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
    
</script>
<?php 
	jimport('joomla.application.component.view');
	//thuc hien goi  model phu hop
	class sale_tsc_orderViewsu_luoc_ban_hang extends JView
	{
		function display($tpl=null)
		{
            if(isset($_POST['datepicker']))
            {
                $date = $_POST['datepicker'];
            }
            else
            {
                $date = null;
            }
            $model = $this->getModel();
            $data = $model->ds_don_hang($date);
            //print_r($data);
            $tong_tien_truoc_den_gio = $model->tong_tien_truoc_den_gio();
           echo "Tổng doanh thu: ";
           $tong_tien_truoc_den_gio = floor($tong_tien_truoc_den_gio);
           echo number_format($tong_tien_truoc_den_gio, 0, ',', '.');
           echo "<br/>";
           echo "Doanh thu trong ngày: ";$tong_tien_trong_ngay = $model->tong_tien_trong_ngay();
           echo  number_format($tong_tien_trong_ngay, 0, ',', '.');
           echo "<br />";

            ?>
            <br /><input type="button" class="button1" onclick="return order()" value="ORDER" />
            <form method="post" action="index.php/?option=com_sale_tsc_order&task=su_luoc_ban_hang">
            <p>Date:<input type="text" id="datepicker" name="datepicker" value="<?php echo $date;?>"/>
            <input type="submit" value="Gửi" /></p></form>
            <table border="1">
                <tr>
                    <td>
                        Mã order
                    </td>
                    <td>
                        Sản phẩm order
                    </td>
                     <td>
                        Trạng thái
                    </td>
                </tr>
                <form action="index.php?option=com_sale_tsc_order" method="post" name="frm1">
                    <input type="hidden" name="option" id="option" value="com_sale_tsc_order" />
                    <input name="task" type="hidden" />
                    <input type="hidden" name="view" id="view" value="su_luoc_ban_hang" />
                    <input type="hidden" name="id_bill" id="id_bill" value="" />
                </form>
            <?php
            foreach($data as $row)
            {
                ?>
                
                    <tr>
                        <td>
                            <?php echo $row->id_order;?>
                        </td>
                        <td>
                            <?php 
                                $data2 = $model->ds_sp_bill($row->id);//echo $row->id;
                                //print_r($data2);
                                ?>
                                    <table border ="1">
                                    <?php 
                                        foreach($data2 as $row2)
                                        {
                                            ?>
                                                <tr>
                                                    <td>
                                                        <?php echo $row2->pro_name;?>
                                                    </td>
                                                    <td>
                                                        <?php echo $row2->number;?>
                                                    </td>
                                                    
                                                </tr>
                                            <?php
                                        }
                                    ?></table>
                                <?php
                            ?>
                        </td>
                        <td>
                            <?php 
                                if($row->status==1)
                                    echo "Mới order";
                                else if($row->status==2)
                                    echo "Đã chế biến xong";
                                else if($row->status==3)
                                    echo "Đã giao";
                                else
                                    echo "Đã thanh toán";  
                            ?>
                        </td>
                        <td>
                        <?php 
                            if($row->status==1)
                                {?>
                                    <input type="button" value="Xóa" onclick="submit_form('xoa',<?php echo $row->id;?>)"  />
                                <?php }
                            else if($row->status==2){
                            ?>
                                <input type="button" value="Chuyển"  onclick="submit_form('chuyen',<?php echo $row->id;?>)"  />
                            <?php }
                        ?>
                        </td>
                    </tr>
                <?php 
            }?>
                </table>
            <?php
		}	
	}
?>